//
//  NewMySelfHeadCell.m
//  QoilPublic
//
//  Created by SunChao on 2018/1/19.
//  Copyright © 2018年 孙超. All rights reserved.
//

#import "NewMySelfHeadCell.h"
#import "UIButton+WebCache.h"
#import "QTopupMoneyVC.h"
#import "BalanceVC.h"
@interface NewMySelfHeadCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headImgView;//头像
@property (weak, nonatomic) IBOutlet UILabel *nickNameLabel;
@property (weak, nonatomic) IBOutlet UIButton *editBtn;

@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;
@property (weak, nonatomic) IBOutlet UIButton *rechargeBtn;//充值按钮
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
@property (weak, nonatomic) IBOutlet UIView *bgView;


@end
@implementation NewMySelfHeadCell
- (IBAction)rechargeBtnAction:(UIButton *)sender {
    
    NSLog(@"rechargeBtnAction");
    QTopupMoneyVC *money = [[QTopupMoneyVC alloc] init];
    UIViewController *vc = [QViewUtility getCurrentVC];
    [vc.navigationController pushViewController:money  animated:YES];
    
}
- (IBAction)editBtnAction:(UIButton *)sender {
    
    NSLog(@"editBtnAction");
    if(self.headBlock){
        self.headBlock();
    }
}
- (void)setFrame:(CGRect)frame
{
    CGFloat kTableViewCellMargin = 5;
    frame.size.height -= kTableViewCellMargin;
    [super setFrame:frame];
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.bgView.userInteractionEnabled = YES; self.backgroundImageView.userInteractionEnabled = YES;
    self.headImgView.layer.cornerRadius = 20;
    self.headImgView.layer.masksToBounds = YES;
    [self.nickNameLabel setFont:[UIFont systemFontOfSize:25 weight:UIFontWeightBold ]];
    [self.nickNameLabel setTextColor:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    
    [self.backgroundImageView addGestureRecognizer:tap];
    self.backgroundImageView.userInteractionEnabled = YES;
    
    
}

- (void)tapAction{
    
    NSLog(@"tap");
    BalanceVC *balance = [[BalanceVC alloc]init];
    UIViewController *vc = [QViewUtility getCurrentVC];
    [vc.navigationController pushViewController:balance animated:YES];
    
}

- (void)setLoginModel:(QLoginModel *)loginModel{
    _loginModel = loginModel;
    if(_loginModel){
        
        self.nickNameLabel.hidden = NO;
        self.headImgView.hidden = NO;
        self.bgView.hidden = NO;
        self.editBtn.hidden = NO;
        self.backgroundColor = [UIColor whiteColor];
        self.moneyLabel.text =  _loginModel.balance;
        if(_loginModel.nickName.length > 0){
            _nickNameLabel.text = _loginModel.nickName;
        }else{
            _nickNameLabel.text = [QUserInfo sharedInfo].loginModel.tel;
        }
        if(_loginModel.headImg.length > 0){
            [self.headImgView sd_setImageWithURL:[NSURL URLWithString:loginModel.headImg] placeholderImage:[UIImage imageNamed:@"head_icon"]];

        }else{
            [self.headImgView setImage:[UIImage imageNamed:@"head_icon"]];
        }
    }else{
        
        self.nickNameLabel.hidden = YES;
        self.headImgView.hidden = YES;
        self.bgView.hidden = YES;
        self.editBtn.hidden = YES;
        self.backgroundColor = [UIColor groupTableViewBackgroundColor];
    }
       

}

@end
